package org.abettor.nookinfo;

import org.abettor.nookinfo.joke.JokeCategory;
import org.abettor.nookinfo.novel.NovelSelect;
import org.abettor.nookinfo.photo.PhotoSelect;
import org.abettor.nookinfo.service.NovelDownloadService;
import org.abettor.nookinfo.service.PhotoUpdateReceiver;
import org.abettor.nookinfo.wiki.RecentTerms;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;

/**
 * 程序入口类，显示主菜单界面
 * @author shawn
 *
 */
public class NookInfo extends Activity
{
	@Override
	public void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		//	为了不让文章下载服务停止，在这里就创建它
		Intent novelIntent = new Intent();
		novelIntent.setClass(this, NovelDownloadService.class);
		startService(novelIntent);

		//	把图片更新检查事件启动起来
		PhotoUpdateReceiver.registerReceiverAlarm(this);
	}

	/**
	 * 点击“图片”按钮的事件处理方法
	 * @param v
	 */
	public void onImageClicked(View v)
	{
		Intent imageIntent = new Intent();
		imageIntent.setClass(this, PhotoSelect.class);
		startActivity(imageIntent);
	}

	/**
	 * 点击“文学”按钮的事件处理方法
	 * @param v
	 */
	public void onNovelClicked(View v)
	{
		Intent novelIntent = new Intent();
		novelIntent.setClass(this, NovelSelect.class);
		startActivity(novelIntent);
	}

	/**
	 * 点击“笑话”按钮的事件处理方法
	 * @param v
	 */
	public void onJokeClicked(View v)
	{
		Intent jokeIntent = new Intent();
		jokeIntent.setClass(this, JokeCategory.class);
		startActivity(jokeIntent);
	}

	/**
	 * 点击“百科”按钮的事件处理方法
	 * @param v
	 */
	public void onWikiClicked(View v)
	{
		Intent wikiIntent = new Intent();
		wikiIntent.setClass(this, RecentTerms.class);
		startActivity(wikiIntent);
	}

	/**
	 * 点击“访问主页”按钮的事件处理方法
	 * @param v
	 */
	public void onHomepageClicked(View v)
	{
		Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(AddressConstant.WEBSITE_ROOT));
		intent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
		startActivity(intent);
	}
}
